/************************************************************************
Copyright (c) 2011, Nic McDonald
All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met: 
 
1. Redistributions of source code must retain the above copyright 
   notice, this list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above 
   copyright notice, this list of conditions and the following 
   disclaimer in the documentation and/or other materials provided 
   with the distribution. 
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
*************************************************************************
 
 Information:
   File Name  :  fifo_16bit.h
   Author(s)  :  Nic McDonald
   Hardware   :  Any
   Purpose    :  First In First Out Buffer
 
*************************************************************************
 Modification History:
   Revision   Date         Author    Description of Revision
   1.00       05/30/2011   NGM       initial
 
************************************************************************/
#ifndef _FIFO_16BIT_H_
#define _FIFO_16BIT_H_
 
/* includes */
#include <stdint.h>
#include <stdlib.h>
#include "rtdef.h"
 

 
/* typedefs */
typedef struct {
    volatile uint32_t size;
    volatile uint16_t * data;
    volatile uint32_t putIndex;
    volatile uint32_t getIndex;
    volatile uint32_t used;
} FIFO;
 
/* functions */
void fifo_init(FIFO* f, uint32_t size, uint16_t * data);
size_t fifo_isFull(FIFO * f);
size_t fifo_isEmpty(FIFO * f);
size_t fifo_contain(FIFO* f);
size_t fifo_remain(FIFO* f);
size_t fifo_size(FIFO* f);
void fifo_clear(FIFO* f);
size_t fifo_getchar(FIFO * f, uint16_t * ch);
uint16_t fifo_peek(FIFO * f, uint16_t index);
size_t fifo_putchar(FIFO * f, const uint16_t ch);
size_t fifo_put(FIFO * f, uint16_t * ptr, size_t length);
size_t fifo_get(FIFO * f, uint16_t * ptr, size_t length);
 
#endif // _FIFO_H_


